package exception;

public class FullConstructors {
    public static void f() throws MyException {
        System.out.println("Throwing MyException from f()");
        throw new MyException();
    }

    public static void g() throws MyException{
        System.out.println("Throwing MyException from g()");
        throw new MyException("Originated in g()");
    }

    public static void main(String[] args) {
        try {
            f();
        }catch (MyException e) {
            e.printStackTrace(System.out);
        }finally {
            System.out.println("this finally code");
        }

        try {
            g();
        }catch (MyException e) {
            e.printStackTrace(System.out);
        }

        try {
            int i = 10/0;
            System.out.println("i= " + i);
        }catch (ArithmeticException e) {
            System.out.println("Caught Exception");
            System.out.println("e.getMessage(): " + e.getMessage());
            System.out.println("e.toString(): " + e.toString());
            System.out.println("e.printStackTrace(): ");
            e.printStackTrace();
        } finally {
            System.out.println("run finally");
        }/* Output:
            Caught Exception
            e.getMessage(): / by zero
            e.toString(): java.lang.ArithmetricException: / by zero
            e.printStackTrace():
            java.lang.ArithmetricException: / by zero
                at Demo.main(Demo.java:6)
            run finally
        */
    }
}
